package com.zyh.flink.day02.source;

import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.ArrayList;
import java.util.Collections;

public class TextStreamTest {
    public static void main(String[] args) throws Exception{
        StreamExecutionEnvironment executionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment();

        //从文件中加载数据转换为数据源
        DataStreamSource<String> dataStream = executionEnvironment.readTextFile("d://");

        SingleOutputStreamOperator<Tuple2<String, Integer>> result = dataStream.map(value -> Tuple2.of(value, 1)).returns(Types.TUPLE(Types.STRING,Types.INT))
                .keyBy(0)
                .sum(1).returns(Types.TUPLE(Types.STRING,Types.INT));
        result.print();
        executionEnvironment.execute("a");
    }
}
